package org.flashIso.engine.core {
	import org.flashIso.engine.base.IsoPerspective;

	/**
	 * 
	 * Point3D represents a point in a 3D space.
	 * 
	 */
	public class Point3D extends ValidateableObject {
		private var _x : Number;
		private var _y : Number;
		private var _z : Number;

		public function Point3D(x : Number = 0, y : Number = 0, z : Number = 0) {
			super();
			this._x = x;
			this._y = y;
			this._z = z;
		}

		public function normalize() : void {
			var r : Number = 1 / Math.sqrt(_x * _x + _y * _y + _z * _z);
			_x = _x * r;
			_y = _y * r;
			_z = _z * r;
		}

		public function set x(value : Number) : void {
			if (_x != value) {
				_x = value;
				triggerValidation();
			}
		}

		public function get x() : Number {
			return _x;
		}

		public function set y(value : Number) : void {
			if (_y != value) {
				_y = value;
				triggerValidation();
			}
		}

		public function get y() : Number {
			return _y;
		}

		public function set z(value : Number) : void {
			if (_z != value) {
				_z = value;
				triggerValidation();
			}
		}

		public function get z() : Number {
			return _z;
		}

		public function distanceFrom(p : Point3D) : Number {
			var dx : Number = _x - p.x;
			var dy : Number = _y - p.y;
			var dz : Number = _z - p.z;
			return Math.sqrt(dx * dx + dy * dy + dz * dz);
		}

		public function clone(dx : Number = 0, dy : Number = 0, dz : Number = 0) : Point3D {
			return new Point3D(_x + dx, _y + dy, _z + dz);
		}

		public function equals(p : Point3D) : Boolean {
			return (_x == p.x) && (_y == p.y) && (_z == p.z);
		}
		
		override public function toString() : String {
			return "[Point3D (x : " + Math.round(_x * 100) / 100 + " y : " + Math.round(_y * 100) / 100 + " z : " + Math.round(_z * 100) / 100 + ")]";
		}
	}
}
